#include "dd_object.h"
#include "dd_matrix.h"
#include <stdlib.h>

/* assign mesh and matrix to object, or initialize if they are not given */
int dd_object_init(struct dd_object *o, struct dd_mesh *mesh,
	float mat[16]) {
	(void) mat;

	/* mesh */
	if (mesh == 0) {
		o->mesh = malloc(sizeof(struct dd_mesh));
	}
	else {
		o->mesh = mesh;
	}

	/* matrix */
	/*
	if (mat == 0) {
		o->mat = malloc(sizeof(float[16]));
		dd_matrix_identity(o->mat);
	}
	else {
		o->mat = mat;
	}
*/

	return 0;
}

void dd_object_draw(struct dd_object *o) {

	//Local transformation
	dd_matrix_push();
	dd_matrix_globalmult(o->mat);

	//Mesh drawing
	dd_mesh_draw(o->mesh);

	//Pop matrix
	dd_matrix_pop();
}

